<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <link rel="stylesheet" href="./bootstrap.min.css">
    <title>户籍管理系统</title>
    <style>
        body {
            background: skyblue;
        }

        .container {
            width: 30rem;
            margin: auto;
            position: relative;
            margin-top: 5.333333rem;
        }

        h5{
            text-align: center;
        }


    </style>
</head>

<body>
    <div class="container">
        <h5>户籍管理系统</h5>
        <div class="form">
            <div class="form-item mt-3">
                <label for="name" class="form-label">账号:</label>
                <input type="text" id="name" class="form-control" placeholder="学号/身份证号">
                <div class="invalid-feedback">
                    账号或密码错误！
                </div>
            </div>
            <div class="form-item mt-3">
                <label for="password" class="form-label">密码:</label>
                <input type="password" id="password" class="form-control" placeholder="密码">
                <div class="invalid-feedback">
                    账号或密码错误！
                </div>
            </div>
            <div class="form-check mt-3">
                <input class="form-check-input" type="checkbox" id="mdl">
                <!-- checked：默认勾选 -->
                <label class="form-check-label" for="mdl">
                    记住账号和密码
                </label>
            </div>
            <div class="form-item mt-3 d-grid">
                <button class="btn btn-primary btn" >登录</button>
            </div>
            <div class="mt-3">
                <h6>还没有账号？先去<a href="reg.html">注册</a></h6>
            </div>
        </div>
    </div>

    <script src="./ajaxfz.js"></script>
    <script>
        const name = document.querySelector('#name')
        const password = document.querySelector('#password')
        const btn = document.querySelector('.btn')

        btn.onclick = async function () {
            const data = await request({
                url: '/login',
                data: {
                    name: name.value,
                    password: password.value
                }
            })
            if (data.code === 200) {
               
                location.href = 'index.html'
            } else if (data.code === 400) {
                name.classList.add('is-invalid')
                password.classList.add('is-invalid')
            }

            console.log('data=', data)
        }
    </script>

</body>

</html>